package com.cgwx.systemservice.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.cgwx.commonutils.result.SysResult;
import com.cgwx.springsecurity.entity.SysLoginLog;
import com.cgwx.springsecurity.entity.SysLoginLogQueryVo;
import com.cgwx.springsecurity.service.SysLoginLogService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 系统访问记录 前端控制器
 * </p>
 *
 * @author GaoWei
 * @since 2023-10-12
 */

@Api(tags = "系统访问记录前端控制器")
@RestController
@RequestMapping("/system/sysLoginLog")
@CrossOrigin
public class SysLoginLogController {

    @Autowired
    private SysLoginLogService sysLoginLogService;

//    供其他模块远程调用
    @ApiOperation("操作日志记录")
    @PostMapping("recordLoginLog/{username}/{status}/{ipaddr}/{message}")
    public SysResult recordLoginLog(
            @ApiParam(name = "username", value = "用户名")
            @PathVariable("username") String username,
            @ApiParam(name = "status", value = "用户状态")
            @PathVariable("status") Integer status,
            @ApiParam(name = "ipaddr", value = "IP地址")
            @PathVariable("ipaddr") String ipaddr,
            @ApiParam(name = "message", value = "用户信息")
            @PathVariable("message") String message) {
        sysLoginLogService.recordLoginLog(username, status, ipaddr, message);
        return SysResult.ok();
    }

//    供其他模块远程调用
    @ApiOperation(value = "获取分页列表")
    @GetMapping("selectPage/{page}/{limit}")
    public IPage<SysLoginLog> selectPage(
            @ApiParam(name = "page", value = "当前页码", required = true)
            @PathVariable("page") Long page,

            @ApiParam(name = "limit", value = "每页记录数", required = true)
            @PathVariable("limit") Long limit,

            @ApiParam(name = "sysLoginLogQueryVo", value = "查询对象")
                    SysLoginLogQueryVo sysLoginLogQueryVo) {
        Page<SysLoginLog> pageParam = new Page(page,limit);
        return sysLoginLogService.selectPage(pageParam,sysLoginLogQueryVo);
    }

//    条件分页查询登录日志
    @ApiOperation(value = "获取分页列表")
    @GetMapping("{page}/{limit}")
    public SysResult index(
            @ApiParam(name = "page", value = "当前页码", required = true)
            @PathVariable long page,

            @ApiParam(name = "limit", value = "每页记录数", required = true)
            @PathVariable long limit,

            @ApiParam(name = "sysLoginLogQueryVo", value = "查询对象")
                    SysLoginLogQueryVo sysLoginLogQueryVo) {
        Page<SysLoginLog> pageParam = new Page(page,limit);
        IPage<SysLoginLog> pageModel =  sysLoginLogService.selectPage(pageParam,sysLoginLogQueryVo);
        return SysResult.ok(pageModel);
    }
}

